package com.leyou.search.web;

import com.leyou.search.dto.SearchDTO;
import com.leyou.search.pojo.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class SearchController {

    private final SearchService searchService;

    public SearchController(SearchService searchService){
        this.searchService = searchService;
    }

    /**
     * 自动提示
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public Mono<List<String>> suggestion(@RequestParam("key")String key){

        return this.searchService.suggestion(key);
    }

    /**
     * 查询数据
     * @param searchDTO
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> list(
            @RequestBody SearchDTO searchDTO){

        return this.searchService.list(searchDTO);
    }


    /**
     * 根据查询条件获取过滤参数信息
     * @param searchDTO
     * @return
     */
    @PostMapping("/filter")
    public Mono<Map<String,List<?>>> filter(
            @RequestBody SearchDTO searchDTO){

        return this.searchService.filter(searchDTO);
    }

}
